<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\CustomerInfo;

class PushClueToLMS implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $clue;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(CustomerInfo $customerInfo)
    {
        $this->clue = $customerInfo;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if (app()->environment('production')) {
            $lms_service = app('LmsService');
            $clue_id = 'dfjk' . $this->clue->id;
            $name = $this->clue->name;
            if ($this->clue->referee_id) {
                $name .= '（来源：推荐官）';
            }
            // 推送至lms
            $r = $lms_service->pushClue($this->clue->vehicle->name, $this->clue->vehicle->series->series_name, $clue_id, $this->clue->phone, $name, $this->clue->dealer->code);
            if ($r) {
                $this->clue->is_push_lms = true;
                $this->clue->save();
            }
        }
    }
}
